//
//  RigisterViewController.swift
//  DollBuy
//
//  Created by 郑东喜 on 2016/11/22.
//  Copyright © 2016年 郑东喜. All rights reserved.
//

import UIKit

class RigisterViewController: TableBaseViewController,RigisterDelegate,TableDelegate {
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        //隐藏导航栏
        self.navigationController?.navigationBar.isHidden = false
        
        //设置导航栏背景颜色透明
        UIApplication.shared.statusBarStyle = UIStatusBarStyle.default
        
        //继承基础类的代理
        self.t_delegate = self
        
        //取消返回手势,防止用户不小心返回页面，输入的个人信息丢失
        self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
    }
    
    //页面结束后，恢复左滑手势
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        
        self.navigationController?.interactivePopGestureRecognizer?.isEnabled = true
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        //设置标题
        self.navigationItem.title = "注册"
        
        //修改导航栏背景色
        self.navigationController?.navigationBar.barTintColor =
            UIColor.white
                tableView.separatorStyle = UITableViewCellSeparatorStyle.none
        tableView.backgroundColor = UIColor.gray
        setUI()
    }

}

// MARK:- 设置UI
extension RigisterViewController{
    func setUI() -> Void {
        let rigV = RigisterView()
        
        rigV.frame = view.bounds
        
        rigV.delegate = self
        view.addSubview(rigV)
    }
}

// MARK:- 监听代理
extension RigisterViewController {
    func rigSuccess() {
        
        print("注册成功")
        LoginModel.shared.loginStatus = "true"
        
        self.navigationController!.popToRootViewController(animated: true)
//        self.navigationController?.popToViewController(LoginView(), animated: true)
    }
}

// MARK:- 实现基类的方法
extension RigisterViewController {
    func click() {
        
        let alert = UIAlertController.init(title: "提示", message: "您确定要放弃当前编辑的内容么?", preferredStyle: .alert)
        
        
        alert.addAction(UIAlertAction.init(title: "放弃编辑", style: .destructive, handler: { (nil) in
            //            self.navigationController!.popViewController(animated: true)
            // pop here
            if let navController = self.navigationController {
                navController.popViewController(animated: true)
            }
        }))
        
        alert.addAction(UIAlertAction.init(title: "留在此页", style: .default, handler: nil))
        
        self.navigationController?.present(alert, animated: true, completion: nil)
        

    }

}
